<template>
  <basic-container>
    <avue-crud
      :option="option"
      :data="data"
      :page.sync="page"
      :search.sync="query"
      :permission="permissionList"
      :before-open="beforeOpen"
      :table-loading="loading"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
    </avue-crud>
  </basic-container>
</template>

<script>
import { getList } from '@/api/warehouse/rawMaterialsScrapRecord';
import { mapGetters } from 'vuex';

export default {
  components: {},
  data() {
    return {
      form: {},
      query: {},
      exportParams: {},
      loading: true,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      data: [],
      option: {
        height: 'calc(100vh - 366px)',
        columnBtn: false,
        calcHeight: 30,
        tip: false,
        refreshBtn: true, //刷新按钮是否显示
        searchBtn: true, // 显示查询的按钮
        border: true,
        index: true,
        dialogClickModal: false,
        addBtn: false,
        delBtn: false,
        editBtn: false,
        viewBtn: false,
        width: '100',
        menu: false,
        searchLabelWidth: 100,
        searchMenuPosition: 'right',
        searchMenuSpan: 18,
        searchSpan: 6,
        searchShow: true,
        indexLabel: '序号',
        column: [
          //   {
          //     label: '操作类型',
          //     prop: 'scrapType',
          //     search: true,
          //     searchOrder: 4
          //   },
          {
            label: '仓库名称',
            prop: 'warehouseName'
          },
          {
            label: '包装条码',
            prop: 'packingSn',
            search: true,
            searchOrder: 5
          },
          {
            label: '物料编码',
            prop: 'partNo',
            search: true,
            searchOrder: 2
          },
          {
            label: '物料名称',
            prop: 'partName'
          },
          {
            label: '物料规格',
            prop: 'partSpec',
            search: true,
            searchOrder: 3
          },

          {
            label: '报废数量',
            prop: 'scrapQuantity'
          },
          {
            label: '操作人',
            prop: 'scrapByName'
          },
          {
            label: '报废时间',
            prop: 'scrapTime',
            searchType: 'datetimerange',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss',
            startPlaceholder: '开始日期',
            endPlaceholder: '结束日期',
            searchSpan: 8,
            searchOrder: 1,
            search: true
          },
          {
            label: '报废原因',
            prop: 'scrapReason'
          }
        ]
      }
    };
  },
  filters: {},
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {};
    }
  },
  methods: {
    beforeOpen(done, type) {
      done();
    },
    searchReset(params, done) {
      this.query = {};
      this.page = {
        pageSize: 20,
        currentPage: 1,
        total: 0
      };
      this.onLoad(this.page, this.query);
      done();
    },
    searchChange(params, done) {
      if (params.scrapTime) {
        params.startTime = params.scrapTime[0];
        params.endTime = params.scrapTime[1];
        delete params.scrapTime;
      }
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, this.query);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page);
    },
    refreshChange() {
      this.onLoad(this.page);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query))
        .then((res) => {
          const data = res.data.data;
          this.data = data.records;
          this.page.total = data.total;
        })
        .finally(() => {
          this.loading = false;
        });
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },

  watch: {}
};
</script>
<style lang="scss" scoped>
::v-deep .el-card__body {
  .avue-crud__menu {
    display: none;
  }
}
</style>
